<%--
  Created by IntelliJ IDEA.
  User: zhangyuan
  Date: 2020-03-13
  Time: 14:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文章搜索结果</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <div style="padding: 8px;">
        <div style="text-align: right">
            <button type="button" class="layui-btn layui-btn-sm" name="thisforum">返回本讨论区</button>
            <button type="button" class="layui-btn layui-btn-sm" name="forum" >返回讨论区列表</button>
        </div>
        <table id="demo" lay-filter="test"></table>
    </div>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="transfer">转移</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
        {{#  if(d.top == 1 ){ }}
        <a class="layui-btn layui-btn-xs" lay-event="top">取消置顶</a>
        {{#  }else{ }}
        <a class="layui-btn layui-btn-xs" lay-event="top">置顶</a>
        {{#  } }}
        {{#  if(d.jing == 1 ){ }}
        <a class="layui-btn layui-btn-xs" lay-event="spirit">取消精华</a>
        {{#  }else{ }}
        <a class="layui-btn layui-btn-xs" lay-event="spirit">设置精华</a>
        {{#  } }}
    </script>
    <script>
        var boardId = $.GetRequest().boardId
        var type = decodeURI($.GetRequest().type)
        var subject = decodeURI($.GetRequest().subject)
        var content = decodeURI($.GetRequest().content)
        var attachmentName = decodeURI($.GetRequest().attachmentName)
        var startSubmitTime = decodeURI($.GetRequest().startSubmitTime)
        var endSubmitTime = decodeURI($.GetRequest().endSubmitTime)

        layui.use(['table','form'], function(){
            var table = layui.table;
            var form = layui.form;
            //第一个实例
           var tableIns= table.render({
                elem: '#demo'
                ,url: '/bbs/selByCon' //数据接口
                ,where:{
                    boardId:boardId,
                    type:type,
                    subject:subject,
                    content:content,
                    attachmentName:attachmentName,
                    startSubmitTime:startSubmitTime,
                    endSubmitTime:endSubmitTime
                }
                ,page: true //开启分页
                ,cols: [[ //表头
                    {field: 'authorName', title: '作者', }
                    ,{field: 'trueName', title: '实名', }
                    ,{field: 'type', title: '分类', }
                    ,{field: 'subject', title: '标题',templet: function(d){
                           if(d.top==1 && d.jing==1){
                               return '<span style="color: red">'+d.subject+'(精)'+'</span>'
                           }else  if(d.top==1 && d.jing==0){
                               return '<span style="color: red;">'+d.subject+'</span>'
                           }else  if(d.top==0 && d.jing==1){
                               return '<span style="color: #1687cb;">'+d.subject+'<span style="color: red">(精)</span>'+'</span>'
                           }else  if(d.top==0 && d.jing==0){
                               return '<span style="color: #1687cb;">'+d.subject+'</span>'
                           }
                       } }
                    ,{field: 'textNums', title: '字节', }
                   ,{title: '回/阅', align:"center",templet:function (d){
                           return d.replyCont+"/"+d.readCont;
                       }
                   }
                    ,{field: 'submitTime', title: '发表时间', }
                    ,{ title: '操作',align:'center', toolbar: '#barDemo',minWidth:350} //这里的toolbar值是模板元素的选择器
                ]]
                ,parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "data": res.obj //解析数据列表
                    };
                }
            });
            //监听工具条
            table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
                console.log(data)

                if(layEvent === 'transfer'){ //转移
                    layer.open({
                        type: 1
                        ,area :['400px', '250px']
                        ,title: '帖子转移'
                        ,content: '<div style="margin-top: 20px;">' +
                            '<form class="layui-form" >' +
                            ' <div class="layui-inline">\n' +
                            '      <label class="layui-form-label">转移至：</label>\n' +
                            '      <div class="layui-input-inline">\n' +
                            '        <select name="modules" lay-verify="required" lay-search="">\n' +
                            '        </select>\n' +
                            '      </div>\n' +
                            '    </div>' +
                            '</form>' +
                            '</div>'
                        ,btn: ['确定', '取消']
                        ,success: function(layero, index){
                            $.get('/bbs/Transfer',{boardId:boardId},function(res){
                                if (res.flag){
                                    var option='';
                                    var obj=res.obj;
                                    for (var i=0;i<obj.length;i++){
                                        option+='<option value="'+obj[i].BOARD_ID+'">'+obj[i].BOARD_NAME+'</option>';
                                    }
                                    $('select[name="modules"]').append(option);
                                    form.render('select');
                                }
                            });
                        }
                        ,yes: function(index, layero){
                            //按钮【按钮一】的回调
                            var modul=$('select[name="modules"]').val();
                            $.post('/bbs/updatefine',{ids:str,Field:"BOARD_ID",status:modul},function(res){
                                if(res.flag){
                                    layer.msg('转移成功!', {icon:1, time: 2000});
                                    tableIns.reload();
                                    layer.close(index);
                                }
                            });
                        }
                    });
                } else if(layEvent === 'edit'){ //编辑
                    layer.open({
                        type: 2
                        ,title: ['编辑', 'font-size:18px;']
                        ,maxmin:true
                        ,area: ['90%', '90%']
                        ,content: '/bbs/allNotice?boardId='+boardId+'&commentId='+data.commentId
                        ,btn:['保存','关闭']
                        ,btnAlign: 'c'
                        ,yes: function(index, layero){
                            //按钮【按钮一】的回调
                            var iframeWin = window[layero.find('iframe')[0]['name']];
                            iframeWin.editOver();
                            layer.close(index)
                            window.location.reload()
                        }
                    });
                } else if(layEvent === 'del'){ //删除
                    layer.confirm('确认要删除该条数据吗？', function(index){
                        $.post('/bbs/delCom',{commentIds:data.commentId},function(res){
                            tableIns.reload()
                        });
                        layer.close(index);
                    });
                } else if(layEvent === 'top'){
                    layer.open({
                        type: 1
                        ,area :['350px', '200px']
                        ,title: '是否置顶'
                        ,content: '<div style="margin-top: 20px;" class="layui-form" >' +
                            ' <div class="layui-form-item">\n' +
                            '    <label class="layui-form-label">是否置顶</label>\n' +
                            '    <div class="layui-input-block">\n' +
                            '      <input type="radio" name="isTopIn" value="1" title="置顶" checked>\n' +
                            '      <input type="radio" name="isTopIn" value="0" title="取消置顶" >\n' +
                            '    </div>\n' +
                            '  </div>'+
                            '</div>'
                        ,btn: ['确定', '取消']
                        ,success: function(layero, index){
                            form.render()
                        }
                        ,yes: function(index, layero){
                            $.ajax({
                                url:'/bbs/updatefine',
                                type: "post",
                                dataType: "json",
                                data:{
                                    ids:data.commentId,
                                    Field:'TOP',
                                    status:$('input[name="isTopIn"]:checked').val()
                                },
                                success:function (res) {
                                    if(res.flag){
                                        layer.msg($('input[name="isTopIn"]:checked').attr('title')+'成功！',{icon:1, time: 2000}, function(){
                                            tableIns.reload()
                                            layer.close(index)
                                        });
                                    }
                                }
                            })
                        }
                    });
                }else if(layEvent === 'spirit'){
                    layer.open({
                        type: 1
                        ,area :['350px', '200px']
                        ,title: '是否加精'
                        ,content: '<div style="margin-top: 20px;" class="layui-form" >' +
                            ' <div class="layui-form-item">\n' +
                            '    <label class="layui-form-label">是否加精</label>\n' +
                            '    <div class="layui-input-block">\n' +
                            '      <input type="radio" name="isSpiritIn" value="1" title="加精" checked>\n' +
                            '      <input type="radio" name="isSpiritIn" value="0" title="取消加精" >\n' +
                            '    </div>\n' +
                            '  </div>'+
                            '</div>'
                        ,btn: ['确定', '取消']
                        ,success: function(layero, index){
                            form.render()
                        }
                        ,yes: function(index, layero){
                            $.ajax({
                                url:'/bbs/updatefine',
                                type: "post",
                                dataType: "json",
                                data:{
                                    ids:data.commentId,
                                    Field:'JING',
                                    status:$('input[name="isSpiritIn"]:checked').val()
                                },
                                success:function (res) {
                                    if(res.flag){
                                        layer.msg($('input[name="isSpiritIn"]:checked').attr('title')+'成功！',{icon:1, time: 2000}, function(){
                                            tableIns.reload()
                                            layer.close(index)
                                        });
                                    }
                                }
                            })
                        }
                    });
                }
            });

        });
        //返回本讨论区
        $("button[name='thisforum']").click(function(){
            window.location.href="/bbs/theme?boardId="+boardId;
        });
        //返回讨论区列表
        $("button[name='forum']").click(function(){
            window.location.href="/bbs/index";
        });
    </script>
</body>
</html>
